﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Fjaspx.UI.Web.Admin.FriendLink
{
    public partial class IframUpLoad : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (FileUpload1.PostedFile != null)
            {
                string Url = "Upload/Link/";
                string filename;//文件名字
                string hz;
                string newname;
                filename = FileUpload1.FileName;
                //取后最
                int pos = filename.IndexOf(".");
                hz = filename.Substring((pos + 1)).ToLower();

                if (hz != "gif" && hz != "jpg" && hz != "jpeg" && hz != "bmp")
                {

                    Response.Write("<script>alert('图片只支持－－－gif|jpg|jpeg|bmp');location.href='IframUpLoad.aspx';</script>");
                    Response.End();

                }
                newname = sjname() + "." + hz;
                //保存图片
                string pathurl;
                pathurl = Server.MapPath("~") + "\\Upload\\Link\\" + newname;
                string kb = FileUpload1.FileContent.Length.ToString();

                FileUpload1.PostedFile.SaveAs(pathurl);
                Response.Write("<script>parent.document.aspnetForm.ctl00_ContentPlaceHolderMain_imgUrl.value='" + Url + newname + "';</script>");
            }
        }
        /// <summary>
        /// 产生个随即名称
        /// </summary>
        /// <returns></returns>
        public string sjname()
        {

            string sj = null;
            sj = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.TimeOfDay.Hours.ToString() + DateTime.Now.TimeOfDay.Minutes.ToString() + DateTime.Now.TimeOfDay.Milliseconds.ToString();
            return sj;

        }
    }
}